package com.mdd.admin.controller.order;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.goods.IOrderGoodsService;
import com.mdd.admin.validate.goods.OrderGoodsParam;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.vo.goods.OrderGoodsListVo;
import com.mdd.admin.vo.goods.OrderGoodsDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 订单服务管理
 */
@RestController
@RequestMapping("api/order_goods")
public class OrderGoodsController {

    @Resource
    IOrderGoodsService iOrderGoodsService;

    /**
     * 订单服务列表
     *
     * @author slien
     * @param pageParam 分页参数
     * @param params 搜索参数
     * @return Object
     */
    @GetMapping("/list")
    public Object list(@Validated PageParam pageParam,
                       @RequestParam Map<String, String> params) {
        PageResult<OrderGoodsListVo> list = iOrderGoodsService.list(pageParam, params);
        return AjaxResult.success(list);
    }
    /**
     * 订单服务详情
     *
     * @author slien
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        OrderGoodsDetailVo detail = iOrderGoodsService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 订单服务新增
     *
     * @author slien
     * @param orderGoodsParam 参数
     * @return Object
     */
    @Log(title = "订单服务新增")
    @PostMapping("/add")
    public Object add(@Validated(value = OrderGoodsParam.create.class) @RequestBody OrderGoodsParam orderGoodsParam) {
        iOrderGoodsService.add(orderGoodsParam);
        return AjaxResult.success();
    }

    /**
     * 订单服务编辑
     *
     * @author slien
     * @param orderGoodsParam 参数
     * @return Object
     */
    @Log(title = "订单服务编辑")
    @PostMapping("/edit")
    public Object edit(@Validated(value = OrderGoodsParam.update.class) @RequestBody OrderGoodsParam orderGoodsParam) {
        iOrderGoodsService.edit(orderGoodsParam);
        return AjaxResult.success();
    }

    /**
     * 订单服务删除
     *
     * @author slien
     * @param orderGoodsParam 参数
     * @return Object
     */
    @Log(title = "订单服务删除")
    @PostMapping("/del")
    public Object del(@Validated(value = OrderGoodsParam.delete.class) @RequestBody OrderGoodsParam orderGoodsParam) {
        //iOrderGoodsService.del(orderGoodsParam.getId());
        return AjaxResult.success();
    }

}
